
import React, { useState, useEffect } from "react";
import { message } from 'antd';
import { useNavigate } from 'react-router-dom';

const crontabLists: React.FC = () => { 
  const [token, setToken] = useState<string>('');
  const navigate = useNavigate();

  useEffect(() => {
    // 从localStorage获取用户登录token
    const userToken = localStorage.getItem('token');
    if (userToken) {
      setToken(userToken);
    } else {
      // 如果没有token，显示错误信息并跳转到登录页
      message.error('请先登录');
      navigate('/login');
    }
  }, [navigate]);

  // 如果token为空，显示加载状态
  if (!token) {
    return <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '50vh' }}>加载中...</div>;
  }

  return <iframe 
    src={`http://127.0.0.1:5920#task?token=${token}`} 
    width="100%" 
    style={{border:"none",height:"calc(100vh - 150px)"}}
    frameBorder="0"
  ></iframe>;
};
export default crontabLists;
